package com.example.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.dao.StudentDao;
import com.example.entity.Student;
import com.example.entity.Students;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 卓小建
 * Date: 2018-12-18
 * Time: 11:39
 */
@Component//由spring管理
@WebService(endpointInterface = "com.example.service.StudentService")
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;

    @Override
    public Student getStudent(Integer id) {
        return studentDao.getStudentById(id);
    }

    @Override
    public Students getAllStudent(String ids) {
        Students students = new Students(new ArrayList<Student>());
        JSONObject json = JSONObject.parseObject(ids);
        JSONArray sid = json.getJSONArray("id");
        for(int i = 0; i < sid.size(); i++){
            Integer s = sid.getInteger(i);
            if(s != null){
                students.getStudents().add(studentDao.getStudentById(s));
            }else {
                continue;
            }
        }
        return students;
    }
}
